package alvarodelrosal.chat.client.chataction.infraestructuraremota;

import alvarodelrosal.chat.client.modelo.ChatUser;
import java.util.LinkedList;
import java.util.List;

public class AllUsers {

    private static List<ChatUser> users = new LinkedList();
    
    public static void addUser(ChatUser user) {
        if (existsUser(user.getId())) {
            ChatUser oldUser = getUser(user.getId());
            users.remove(oldUser);
        }
        users.add(user);
    }
    
    public static boolean existsUser(int idUser) {
        for(ChatUser user : users) {
            if(idUser == user.getId()) {
                return true;
            }
        }
        return false;
    }
    
    public static ChatUser getUser(int idUser) {
        for(ChatUser user : users) {
            if(idUser == user.getId()) {
                return user;
            }
        }
        throw new IllegalArgumentException("El usuario no existe, se debió validar antes");
    }
    
    public static void removeAll() {
        users.clear();
    }
    
    public static List<ChatUser> getAllUsers() {
        return users;
    }
    
}
    